package com.camemax.server.service.impl;

import com.camemax.server.pojo.Orders;
import com.camemax.server.service.OrdersCreateService;
import com.camemax.server.service.OrdersRabbitmqService;
import com.camemax.server.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

// ************************
// * @Date: 2021/6/21
// * @Author: Camemax
// * @Description: 订单服务实现类 - 实现订单服务完整流程
// ************************
@Service("ordersCreateServiceImpl")
public class OrdersCreateServiceImpl implements OrdersCreateService {

    @Autowired
    OrdersService orderService;

    @Autowired
    OrdersRabbitmqService rabbitService;

    @Override
    public void createOrder(Orders orderInfo) {
        int orderInsertResult = orderService.insertOrder(orderInfo);
        int reorderInsertResult = orderService.insertRedundancyOrder(orderInfo);
         if (orderInsertResult == 1 && reorderInsertResult == 1 ){
             System.out.println("==== 【订单表写入成功】 ====");
             System.out.println("==== 【冗余备份表写入成功】 ====");
             orderService.updateRedundancyOrderStatus(orderInfo.getOrderId());
             System.out.println("==== 【订单状态修改成功】 ====");
        }
         // 订单信息写入Rabbitmq
         rabbitService.sendMessage(orderInfo);
    }
}
